package com.flightcloud.ssm;

import org.springframework.context.annotation.Bean;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

public class FreemarkerConfig {
	/**
	 * 
	 * 描述 配置freemarker
	 * 
	 * @return
	 *
	 */
	@Bean
	public FreeMarkerConfigurer freeMarkerConfigurer() {
		String templates = "/WEB-INF/templates";
		FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
		configurer.setTemplateLoaderPath(templates);
		ResourceLoader loader = new DefaultResourceLoader();
		configurer.setConfigLocation(loader.getResource("classpath:freemarker.properties"));
		return configurer;
	}

	/**
	 * 
	 * 描述 配置freemarker视图解析器
	 * 
	 * @return
	 *
	 */
	@Bean
	public FreeMarkerViewResolver freemarkerViewResolver() {
		FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver();
		viewResolver.setViewClass(FreeMarkerView.class);
		viewResolver.setCache(false);
		viewResolver.setSuffix(".html");
		viewResolver.setRequestContextAttribute("rc");
		viewResolver.setContentType("text/html;charset=utf-8");
		// 设置视图的优先级，值越小，优先级越高
		viewResolver.setOrder(0);
		return viewResolver;
	}
}
